﻿import { requestApi } from "./m-request";
import { comPortApi } from "./m-comPort";
import { showError } from "./m-sundry";

//返回支付类型文字
function setPayType(PayType) {
    if (!!PayType) {
        switch (PayType) {
            case 'ONLINE':
                return '在线支付'
                break;
            case 'YE':
                return '余额支付'
                break;
            case 'Ye':
                return '余额支付'
                break;
            case 'System':
                return '系统'
                break;
            case 'H5':
                return 'H5支付'
                break;
            case 'NATIVE':
                return '扫码支付'
                break;
            case 'JSAPI':
                return '公众号支付'
                break;
            case 'Alipay':
                return '支付宝支付'
                break;
            case 'Bank':
                return '网上银行支付'
                break;
            case 'UNONLINE':
                return '线下支付'
                break;
            default:
                return '空'
                break;
        }
    }else{
        return '空'
    }
}

// 获取免密支付最低数额
function getNoPwdPayData({ fn = ''}){
    requestApi({
        url: `${comPortApi}/GetFreesecret`
    })
    .then(res => {
        console.log('获取免密支付最低数额 res', res)
        if (res.errcode == 1000) {
            if(typeof fn === 'function') fn(res.data.Freesecret)
        } else {
            showError(res.message)
        }
    }, res => {
        console.log(res)
        if(res.errcode != 2000){
           showError('服务器正在修整')
        }
    })
    .catch(res => {
        console.log(res)
        showError('服务器正在修整，请稍后')
    })
    .finally(() => {
        $('.loader-01').addClass('disnone')
    })
}

// getPayBeforConfig
function getPayBeforConfig({fn = ''}){
    if(typeof fn === 'function'){
        $('.loader-01').removeClass('disnone')
        requestApi({
            url: `${comPortApi}/GetPayConfig`
        })
        .then(res => {
            console.log('获取支付基本信息 res', res)
            if (res.errcode == 1000) {
                if(typeof fn === 'function') fn(res.data)
            } else {
                showError(res.message)
                if(typeof fn === 'function') fn('')
            }
        }, res => {
            console.log(res)
            if(res.errcode != 2000){
               showError('服务器正在修整')
            }
            if(typeof fn === 'function') fn('')
        })
        .catch(res => {
            console.log(res)
            showError('服务器正在修整，请稍后')
            if(typeof fn === 'function') fn('')
        })
        .finally(() => {
            $('.loader-01').addClass('disnone')
        })
    }
}

export {setPayType, getNoPwdPayData, getPayBeforConfig}